<?php
/**
 * Created by PhpStorm.
 * User: xiao
 * Date: 2017/6/15
 * Time: 下午5:19
 */

namespace app\src\consumehistory\logic;


use app\src\accountScore\model\AccountScoreHistory;
use app\src\base\logic\BaseLogic;
use app\src\ConsumeHistory\model\ConsumeHistory;
use app\src\payment\action\PaymentAction;
use app\src\payment\logic\PaymentLogic;
use app\src\seller\logic\SellerLogic;
use app\src\seller\logic\SellerOrderLogic;
use app\src\sellerApply\logic\SellerApplyLogic;

class ConsumeHistoryLogic extends BaseLogic
{


    protected function _init()
    {
        $this->setModel(new ConsumeHistory());
    }



    /*
     * 完成购买后，写入购买记录表
     * order_id=seller_order_id
     */
    public function seller_history($order_code){
        $order=(new SellerOrderLogic())->getInfo(['order_code'=>$order_code,'status'=>'0']);
        if(!empty($order['info'])){
            $order_id=$order['info']['id'];
            $uid=$order['info']['uid'];
            $price=$order['info']['amount'];
            //重复性检测
            $history=$this->getInfo(['uid'=>$uid,'type'=>2,'item_id'=>$order_id]);
            if(!empty($history['info'])) return false;
            $seller=(new SellerLogic())->getInfo(['id'=>$order['info']['seller_id']]);
            $snapshot=[
                'seller_name'=>$seller['info']['name'],
            ];
            $entity=[
                'uid'=>$uid,
                'type'=>'2',
                'item_id'=>$order_id,
                'price'=>$price,
                'snapshot'=>json_encode($snapshot),
                'create_time'=>NOW_TIME,
                'status'=>'0'
            ];
            $consume_history=(new ConsumeHistoryLogic())->add($entity,'');
            if($consume_history['status']) return $this->apiReturnSuc($uid);
            return $this->apiReturnErr($consume_history['info']);
        }

    }

}